<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增任务</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label"> 任务备注 </label>
                <div class="layui-input-block">
                    <input id="taskname"  lay-verify="title" autocomplete="off" placeholder="请输入任务备注" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> 主机编号 </label>
                <div class="layui-input-block">
                        <input id="hostid"  lay-verify="title" autocomplete="off" placeholder="请输入主机编号" class="layui-input">
                </div>
            </div>

            <div  style="float:left;">
                <label class="layui-form-label"> 主机信息 </label>
                <div class="layui-input-block">
                    <input id="hostinfo" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="1">&nbsp;&nbsp;
                </div>
            </div>

            <div  style="float:left;">
                <label class="layui-form-label"> 安全策略 </label>
                <div class="layui-input-block">
                    <input id="gpedit" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="2">&nbsp;&nbsp;
                </div>
            </div>

            <div style="float:left;">
                <label class="layui-form-label"> 补丁信息 </label>
                <div class="layui-input-block">
                    <input id="patchinfo" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="3">&nbsp;&nbsp;
                </div>
            </div>

            <div style="float:left;">
                <label class="layui-form-label"> 网络信息 </label>
                <div class="layui-input-block">
                    <input id="netinfo" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="4">&nbsp;&nbsp;
                </div>
            </div>

            <div style="float:left;">
                <label class="layui-form-label"> 后门核查 </label>
                <div class="layui-input-block">
                    <input id="backdoor" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="5">&nbsp;&nbsp;
                </div>
            </div>

            <div style="float:left;">
                <label class="layui-form-label"> 自启动项 </label>
                <div class="layui-input-block">
                    <input id="selfstart" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="6">&nbsp;&nbsp;
                </div>
            </div>

            <div style="float:left;">
                <label class="layui-form-label"> 服务项 </label>
                <div class="layui-input-block">
                    <input id="service" type="checkbox" name="zzz" lay-skin="switch" lay-text="检测|关闭" value="7">&nbsp;
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        form.on('submit(user-save)', function(data) {
            let taskname = $("#taskname").val()
            let hostid = $("#hostid").val()
            let hostinfo = 0
            let gpedit = 0
            let patchinfo = 0
            let netinfo = 0
            let backdoor = 0
            let selfstart = 0
            let service = 0

            var chk_value =[];//定义一个数组
            $('input[name="zzz"]:checked').each(function(){//遍历每一个名字为nodes的复选框，其中选中的执行函数
                chk_value.push($(this).val());//将选中的值添加到数组chk_value中
            });
            for(let cid = 0; cid < chk_value.length; cid++)
            {
                if(chk_value[cid] === '1') hostinfo = 1;
                else if(chk_value[cid] === '2') gpedit = 1;
                else if(chk_value[cid] === '3') patchinfo = 1;
                else if(chk_value[cid] === '4') netinfo = 1;
                else if(chk_value[cid] === '5') backdoor = 1;
                else if(chk_value[cid] === '6') selfstart = 1;
                else if(chk_value[cid] === '7') service = 1;
            }
            $.ajax({
                url: '/task/insert',
                data: JSON.stringify({
                    "taskname":taskname,
                    "hostid":hostid,
                    "hostinfo":hostinfo,
                    "gpedit":gpedit,
                    "patchinfo":patchinfo,
                    "netinfo":netinfo,
                    "backdoor":backdoor,
                    "selfstart":selfstart,
                    "service":service
                }),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code === 200) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("task-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
